/**
 * 选择排序
 *
 * @param {number[]} nums
 * @return {number[]}
 */
function selectSort(nums) {
  const length = nums.length;
  if (length < 2) {
    return nums;
  }
  let min;
  let temp;
  for (let i = 0; i < length; i++) {
    min = i;
    for (let j = i + 1; j < length; j++) {
      if (nums[j] < nums[min]) {
        min = j;
      }
    }
    temp = nums[i];
    nums[i] = nums[min];
    nums[min] = temp;
  }
  return nums;
}

const nums = [3, 44, 38, 5, 47, 15, 36, 26, 27, 2, 46, 4, 19, 50, 48];
console.log(selectSort(nums));
